package com.hl.toolkit.server.tycoin.account.slaverepository;

import com.tycoin.account.slaveentity.TycoinAccountRecharge;
import com.tycoin.common.repository.AbstractRepository;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
@CacheConfig(cacheNames = "com.tycoin.account.slaverepository.TycoinAccountRechargeRepository")
 public interface TycoinAccountRechargeRepository extends AbstractRepository<TycoinAccountRecharge, Long> {

 
	
	//根据支付方式分组查询
	
	
 	@Query("select t from TycoinAccountRecharge  t WHERE t.userId=:userId      and     (t.paymentTime BETWEEN  :startDay   AND   :endDay)     ORDER BY      t.paymentTime  ASC ")
	List<TycoinAccountRecharge> findBingRechargeToDate(@Param("startDay") String startDay, @Param("endDay") String endDay, @Param("userId") String userId);






 	@Query("select t from TycoinAccountRecharge  t WHERE t.userId=:userId      and     (t.paymentTime BETWEEN  :startDay   AND   :endDay)     ORDER BY      t.paymentTime  ASC ")
	List<TycoinAccountRecharge>AccountPayRechargeToDate(@Param("startDay") String startDay, @Param("endDay") String endDay, @Param("userId") String userId);





 	@Query(" select t from TycoinAccountRecharge t where t.logno = :logno  ")
	List<TycoinAccountRecharge> FindLongo(@Param("logno") String logno);


 	@Query("select t from TycoinAccountRecharge t   WHERE t.userId=:userId      and     (t.paymentTime BETWEEN  :startDay   AND   :endDay)    GROUP BY   t.payMode    ORDER BY      t.payMode ASC ")
 	List<TycoinAccountRecharge> LineRechargeToDate(@Param("startDay") String startDay, @Param("endDay") String endDay, @Param("userId") String userId);


 	@Query("select t from TycoinAccountRecharge t   WHERE t.userId=:userId      and     (t.paymentTime BETWEEN  :startDay   AND   :endDay)   and   t.payMode in(1,2,3,4,5,6)  ORDER BY t.paymentTime DESC ")
 	List<TycoinAccountRecharge> TycoinAccountRechargeToNativeSql(@Param("startDay") String startDay, @Param("endDay") String endDay, @Param("userId") String userId);


	//根据支付方式查询每一种支付方式一天发生的交易金额

 	@Query("select t from TycoinAccountRecharge t  WHERE t.userId=:userId      and     (t.paymentTime BETWEEN  :startDay   AND   :endDay)   ")
 	List<TycoinAccountRecharge>PayRechargeToDate(@Param("startDay") String startDay, @Param("endDay") String endDay, @Param("userId") String userId);


	//查询转账信息

 	@Query("select t from TycoinAccountRecharge  t WHERE t.id=:countLogId  AND  t.userId = :userId")
  	TycoinAccountRecharge findTransferAccountsInfo(@Param("countLogId") Long countLogId, @Param("userId") String userId);






 	TycoinAccountRecharge findOneBylogno(String logno);



	TycoinAccountRecharge findOneBypaymentId(String paymentId);



 	@Query(" select t from TycoinAccountRecharge t where t.paymentTime > :paymentTime ")
	List <TycoinAccountRecharge> queryPaymentTime(@Param("paymentTime") String paymentTime);


 	//查询账单

 	@Query(" select t from TycoinAccountRecharge t where t.userId = :userId  order by t.paymentTime DESC ")
	Page <TycoinAccountRecharge> queryByPage(@Param("userId") String userId, Pageable pageable);


 	@Query(" select t from TycoinAccountRecharge t where t.userId = :userId and t.payMode=:payMode   order by t.paymentTime DESC ")
 	Page <TycoinAccountRecharge> queryPaymentTimeByPayMode(@Param("userId") String userId, @Param("payMode") int payMode, Pageable pageable);

 	@Query(" select t from TycoinAccountRecharge t where t.userId = :userId and t.paymentStatus=:paymentStatus   order by t.paymentTime DESC ")
 	Page <TycoinAccountRecharge> queryPaymentTimeByPaymentStatus(@Param("userId") String userId, @Param("paymentStatus") int payMode, Pageable pageable);

 	@Query(" select t from TycoinAccountRecharge t where t.userId = :userId and t.paymentStatus=:paymentStatus and t.payMode=:payMode  order by t.paymentTime DESC ")
 	Page <TycoinAccountRecharge> queryPaymentTimeByPaymentStatusAndPayMode(@Param("userId") String userId, @Param("paymentStatus") int paymentStatus, @Param("payMode") int payMode, Pageable pageable);

 	
 	List<TycoinAccountRecharge> findByuserId(String userId);
 	
 	/**
 	 * 查询所有的QQ钱包订单
 	 */
 	@Query("select t from TycoinAccountRecharge t where t.userId =:userId and t.payMode=4")
 	List<TycoinAccountRecharge> getOrderInQqByUserId(@Param("userId") String userId);
}
